<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Fetches all rows in a particular result column as an array</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.pg-execute.html">« pg_execute</a></li>
      <li style="float: right;"><a href="function.pg-fetch-all.html">pg_fetch_all »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.pgsql.html">PostgreSQL 函数</a></li>
    <li>Fetches all rows in a particular result column as an array</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.pg-fetch-all-columns" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">pg_fetch_all_columns</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">pg_fetch_all_columns</span> &mdash; <span class="dc-title">Fetches all rows in a particular result column as an array</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.pg-fetch-all-columns-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>pg_fetch_all_columns</strong></span>(<span class="methodparam"><span class="type"><a href="class.pgsql-result.html" class="type PgSql\Result">PgSql\Result</a></span> <code class="parameter">$result</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$field</code><span class="initializer"> = 0</span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>pg_fetch_all_columns()</strong></span> returns an array that
   contains all rows (records) in a particular column of the <span class="classname"><a href="class.pgsql-result.html" class="classname">PgSql\Result</a></span> instance.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数将 NULL 字段设置为 PHP <strong><code>null</code></strong> 值。</span></p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.pg-fetch-all-columns-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">result</code></dt>

     <dd>

      <p class="para">An <span class="classname"><a href="class.pgsql-result.html" class="classname">PgSql\Result</a></span> instance, returned by <span class="function"><a href="function.pg-query.html" class="function">pg_query()</a></span>,
<span class="function"><a href="function.pg-query-params.html" class="function">pg_query_params()</a></span> or <span class="function"><a href="function.pg-execute.html" class="function">pg_execute()</a></span>(among others).</p>
     </dd>

    
    
     <dt>
<code class="parameter">field</code></dt>

     <dd>

      <p class="para">
       Column number. Defaults to the first column if not specified.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.pg-fetch-all-columns-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   An <span class="type">array</span> with all values in the result column.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.pg-fetch-all-columns-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.1.0</td>
 <td>
  现在 <code class="parameter">result</code> 参数接受 <span class="classname"><a href="class.pgsql-result.html" class="classname">PgSql\Result</a></span>
  实例，之前接受 <a href="language.types.resource.html" class="link">资源(resource)</a>。
 </td>
</tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-function.pg-fetch-all-columns-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1902">
    <p><strong>示例 #1 <span class="function"><strong>pg_fetch_all_columns()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"An&nbsp;error&nbsp;occurred.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;title,&nbsp;name,&nbsp;address&nbsp;FROM&nbsp;authors"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"An&nbsp;error&nbsp;occurred.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Get&nbsp;an&nbsp;array&nbsp;of&nbsp;all&nbsp;author&nbsp;names<br /></span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_fetch_all_columns</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.pg-fetch-all-columns-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.pg-fetch-all.html" class="function" rel="rdfs-seeAlso">pg_fetch_all()</a> - 从结果中提取所有行作为一个数组</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>